<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <title>Yes, is it</title>

	<link rel="stylesheet" type="text/css" href="style/default.css" />
</head>
<script type="text/javascript">
	function check(form){
	var s_author = form.author.value;
	if(s_author == "" || s_author == null)
	{
		alert('what\'s your name?');
		return false;
	}
	var s_email = form.email.value;
	if(s_email == "" || s_email == null)
	{
		alert('Please leave me your contact info.');
		return false;
	}
	var s_text = form.text.value;
	if(s_text == "" || s_text == null)
	{
		alert('Do nothing to tell me it?');
		return false;
	}
	this.target="form_reponse"
	return true;
}
</script>

<?php
error_reporting(E_ALL & ~E_NOTICE);
session_start(); 
function set_token() 
	{ 
	 $_SESSION['token'] = md5(microtime(true)); 
	} 
function valid_token() 
	{ 
	 $return = $_REQUEST['token'] === $_SESSION['token'] ? true : false; 
	 set_token(); 
	 return $return; 
	} 
//如果token为空则生成一个token 
if( !isset($_SESSION['token'] ) || $_SESSION['token'] == '' ) 
	{ 
	 set_token(); 
	} 
if(isset($_POST['submit'])){ 
	if(valid_token())
	{
		$mysqli = mysqli_connect("50.62.209.15","tangjing","A299792458b","my_web");
		if (!$mysqli)
		  {
		  die('Could not connect: ' . mysql_error());
		  }

		$sql = "INSERT INTO contact_form (author, email, message) VALUES (?,?,?)";
		$stms = $mysqli->prepare($sql);
		$stms->bind_param('sss',$_POST['author'],$_POST['email'],$_POST['text']);
		$stms->execute();

		if($stms->affected_rows > 0)
		{
			echo "<script>alert('successful!')</script>";
		}
		$stms->close();
		$mysqli->close();
	}
}
?>

<body>
<div id="templatemo_header">
    <div id="site_title"><h1><a href="index.html" title="only for you">Feeling</a></h1></div>
</div>

<div id="templatemo_main">
	<div id="content">
	    <div class="section" id="contact">
		    <h2>Contact</h2>
		    
		    <div class="half left">
			    <h4> Contact me here </h4>
			    <div id="contact_form">
				    <form method="post" name="contact" onsubmit="return check(this)">
					<input type="hidden" name="token" value="<?=$_SESSION['token']?>"> 
				    <div class="left">
					    <label for="author">Name:</label>
					    <input name="author" type="text" class="input_field" id="author" maxlength="40" />
				    </div>
				    <div class="right">
					    <label for="email"> Email:</label>
					    <input name="email" type="text" class="input_field" id="email" maxlength="40" />
				    </div>
				    <div class="clear"></div>
				    <label for="text">Message:</label>
				    <textarea id="text" name="text" rows="0" cols="0"></textarea>
				    <input type="submit" class="submit_btn float_l" name="submit" id="submit" value="Send" />
				    </form>
					<iframe style="display:none" id="form_reponse" name="form_reponse" src="about:blank"></iframe>
			    </div>

		    </div>
		    
		    <div class="half right">
			    <h4>Mailing Address</h4>
			    <strong>广州爱游信息科技有限公司 <a href="http://www.4399.com/" target="_parent">4399</a></strong><br />
			    <strong>Email: enkotangjing@163.com</strong><br />
			    <div class="clear h20"></div>
			    <div class="img_nom img_border">
				    <span></span>
				    <iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://ditu.google.cn/maps?f=d&amp;source=s_d&amp;saddr=23.134265,113.336833&amp;daddr=&amp;hl=zh-CN&amp;geocode=&amp;sll=23.134184,113.336951&amp;sspn=0.001512,0.002476&amp;t=m&amp;brcurrent=3,0x3402fe54c3b0b92d:0x5c08009ef0970334,0,0x340301fe46c655a3:0xc549ef142225757a%3B5,0,0&amp;mra=mift&amp;mrsp=0&amp;sz=19&amp;ie=UTF8&amp;ll=23.134184,113.336951&amp;spn=0.001512,0.002476&amp;output=embed"></iframe><br /><small><a href="http://ditu.google.cn/maps?f=d&amp;source=embed&amp;saddr=23.134265,113.336833&amp;daddr=&amp;hl=zh-CN&amp;geocode=&amp;sll=23.134184,113.336951&amp;sspn=0.001512,0.002476&amp;t=m&amp;brcurrent=3,0x3402fe54c3b0b92d:0x5c08009ef0970334,0,0x340301fe46c655a3:0xc549ef142225757a%3B5,0,0&amp;mra=mift&amp;mrsp=0&amp;sz=19&amp;ie=UTF8&amp;ll=23.134184,113.336951&amp;spn=0.001512,0.002476" style="color:#0000FF;text-align:left">查看大图</a></small>
				    </iframe>
			    </div>
		    </div>
		    
        </div>
	</div>
</div>

<div id="templatemo_footer">
    Copyright © 2013 <a href="contact.html">feeling</a> | Designed by <a href="http://www.templatemo.com" target="_parent">Free CSS</a>
</div>
</body>
</html>